using System;
using System.Windows;
using System.Windows.Media;

namespace RegionExtension
{
    public static class Extensions
    {
        public static string Left(this string value, int length, string show = null)
        {
            if (!string.IsNullOrWhiteSpace(value) && value.Length > length)
            {
                value = value.Substring(0, length) + show;
            }
            return value;
        }

        public static T GetChild<T>(this DependencyObject obj) where T : DependencyObject
        {
            DependencyObject child = null;
            for (Int32 i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
            {
                child = VisualTreeHelper.GetChild(obj, i);
                if (child != null && child.GetType() == typeof(T))
                {
                    break;
                }
                else if (child != null)
                {
                    child = GetChild<T>(child);
                    if (child != null && child.GetType() == typeof(T))
                    {
                        break;
                    }
                }
            }
            return child as T;
        }
    }
}